<template>
  <TableView
    ref="tableView"
    :table-attrs="{
      api: getList,
      descs: ['create_time'],
      dicOptions: [
        { prop: 'status', dicType: 'warehous_status' },
        { prop: 'method', dicType: 'purchase_way' },
        { prop: 'currencyType', dicType: 'currency_type' },
        { prop: 'type', dicType: 'type_document' }
      ]
    }"
    form-path="/asset/warehous/warehousSellForm/{id:-1}"
    :search-model="searchForm"
    :delete-api="batchDelete"
    :toolbar-attrs="{
      buttons: ['slot', { del: 'warehous_warehous_del', create: 'warehous_warehous_add' }]
    }">
    <template #toolbar-button="{selectedRows}">
      <ToolbarButton
        type="primary"
        privilege="warehous_warehous_export"
        icon="el-icon-download"
        label="导出"
        @click="exportExcel()" />
      <ToolbarButton icon="el-icon-printer" type="primary" label="打印" :disabled="selectedRows.length !== 1" @click="assetPrint(selectedRows)" />
    </template>
    <template #columns>
      <TableColumn label="办理状态" prop="status" width="90" />
      <TableColumn label="单据类型" prop="type" width="90" />
      <TableColumn label="冲销单号" clickable prop="caseid" width="125" />
      <TableColumn label="验收单号" clickable prop="parentCaseid" width="125" />
      <TableColumn label="供应商" prop="supplierName" width="100" />
      <TableColumn label="冲销人" prop="createBy" width="80" />
      <TableColumn label="冲销日期" prop="createTime" width="90">
        <template #default="{ row }">
          {{ $formatDate(row.createTime) }}
        </template>
      </TableColumn>
      <TableColumn label="冲销单位" prop="deptFullname" width="160" />
      <TableColumn label="合同或发票" prop="contractName" width="95" />
      <TableColumn label="存放房间" prop="houseName" width="95" />
      <TableColumn label="采购方式" prop="method" width="80" />
      <TableColumn label="冲销总金额" prop="amount" width="100" />
      <TableColumn label="货币类型" prop="currencyType" width="80" />
      <TableColumn label="冲销说明" prop="explains" />
      <TableColumn label="冲销明细" prop="detailed" />
    </template>
    <template #search-form>
      <FormSelect v-model="searchForm.type" dict-type="type_document" label="单据类型" prop="type" />
      <FormSelect v-model="searchForm.status" dict-type="assetAcStatus" label="状态" prop="status" />
      <FormInput v-model="searchForm.caseid" label="冲销单号" prop="caseid" />
      <FormDatePicker v-model="searchForm.inTime" label="冲销时间" :split="false" date-range prop="inTime" />
      <FormInput v-model="searchForm.createBy" label="申请人" prop="createBy" />
      <FormInput v-model="searchForm.deptFullname" label="冲销单位" prop="deptFullname" />
      <FormInput v-model="searchForm.budgetNumber" label="预算编号" prop="budgetNumber" />
      <FormInput v-model="searchForm.budgetName" label="预算名称" prop="budgetName" />
      <FormInput v-model="searchForm.supplierName" label="供应商" prop="supplierName" />
      <FormInput v-model="searchForm.detailed" label="冲销明细" prop="detailed" />
      <FormSelect v-model="searchForm.method" dict-type="asset_purchase_method" label="采购方式" prop="method" />
    </template>
  </TableView>
</template>

<script>
  import { services } from '@/config'
  import { fetchList, batchDelete } from '@/api/asset/warehous'
  import { printReport } from '@/util/print'

  export default {
    name: 'WarehousSellView',
    props: {},
    data() {
      return {
        searchForm: {
          classify: '1',
          type: '',
          status: '',
          purchaseOuname: '',
          caseid: '',
          createTime: '',
          arrivalDatetime: '',
          createBy: '',
          deptFullname: '',
          budgetNumber: '',
          budgetName: '',
          supplierName: '',
          detailed: '',
          method: ''
        },
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20 // 每页显示多少条
        }
      }
    },
    methods: {
      batchDelete,
      getList() {
        return fetchList(Object.assign(this.page, this.searchForm))
      },
      assetPrint(selectedRows) {
        printReport(selectedRows[0], '请选择冲销信息！', 'oss_warehous_sell.ureport.xml')
      },
      exportExcel() {
        this.$downBlobFile(
          `${services.assetService}warehous/export`,
          this.searchForm,
          `冲销单${this.$dateFormat(new Date())}.xlsx`
        )
      }
    }
  }
</script>
